home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2001 / MacHack 2001.toast / pc / The Hacks / DSPanic / PatchIt.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-06-23  |  1.9 KB  |  66 lines

  1. /*
  2.  * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
  3.  *
  4.  * @APPLE_LICENSE_HEADER_START@
  5.  *
  6.  * The contents of this file constitute Original Code as defined in and
  7.  * are subject to the Apple Public Source License Version 1.1 (the
  8.  * "License").  You may not use this file except in compliance with the
  9.  * License.  Please obtain a copy of the License at
  10.  * http://www.apple.com/publicsource and read it before using this file.
  11.  *
  12.  * This Original Code and all software distributed under the License are
  13.  * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
  14.  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
  15.  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
  16.  * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT.  Please see the
  17.  * License for the specific language governing rights and limitations
  18.  * under the License.
  19.  *
  20.  * @APPLE_LICENSE_HEADER_END@
  21.  */
  22. /*
  23.  * MPEnabler - An example of patching funtions in the Mac OS X Kernel
  24.  *
  25.  * Yes, I know that I said you don't patch functions in kernel,
  26.  * but you should remember what your mother used to say,
  27.  *
  28.  *   "Do and I say, not as I do."
  29.  * 
  30.  * Josh de Cesare, MacHack 2000
  31.  */
  32.  
  33. #include <mach/mach_types.h>
  34. #include <vm/vm_kern.h>
  35.  
  36.  
  37.  
  38. extern pmap_t kernel_pmap;
  39.  
  40. typedef int (* PatchProcPtr)();
  41.  
  42. struct Patch {
  43.   long        arg0Save;
  44.   void        *oldFunc;
  45.   void        *newFunc;
  46.   vm_offset_t targetPhys1;
  47.   vm_offset_t targetPhys2;
  48.   long        valid;
  49.   long        patchStub[10];
  50. };
  51. typedef struct Patch Patch, *PatchPtr;
  52.  
  53. #define kPatchSize  (1 << 6)
  54. #define kMaxPatches (PAGE_SIZE >> 6)
  55.  
  56. extern PatchPtr gPatches;
  57.  
  58. extern void InitPatchIt(void);
  59. extern void UnInitPatchIt(void);
  60. extern PatchPtr PatchIt(void *oldFunc, void *newFunc);
  61. extern void UnPatchIt(PatchPtr patch);
  62.  
  63. extern void PatchItHelper(void);
  64. extern void PatchItStub(void);
  65. extern void PatchItFlush(vm_offset_t addr);
  66.